package com.ruoyi.project.system.leaverequest.controller;

import java.util.Date;
import java.util.List;

import com.ruoyi.project.system.drivers.domain.VeDrivers;
import com.ruoyi.project.system.drivers.service.IVeDriversService;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.leaverequest.domain.VeLeaverequest;
import com.ruoyi.project.system.leaverequest.service.IVeLeaverequestService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-01-06
 */
@Controller
@RequestMapping("/system/leaverequest")
public class VeLeaverequestController extends BaseController
{
    private String prefix = "system/leaverequest";

    @Autowired
    private IVeLeaverequestService veLeaverequestService;
    @Autowired
    private IVeDriversService iVeDriversService;
    @RequiresPermissions("system:leaverequest:view")
    @GetMapping()
    public String leaverequest()
    {
        return prefix + "/leaverequest";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:leaverequest:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VeLeaverequest veLeaverequest)
    {
        startPage();
        List<VeDrivers> list = veLeaverequestService.noFinishTask(getUserId());
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:leaverequest:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VeLeaverequest veLeaverequest)
    {
        List<VeLeaverequest> list = veLeaverequestService.selectVeLeaverequestList(veLeaverequest);
        ExcelUtil<VeLeaverequest> util = new ExcelUtil<VeLeaverequest>(VeLeaverequest.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:leaverequest:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VeLeaverequest veLeaverequest)
    {
        veLeaverequest.setApprovalDate(new Date());
        return toAjax(veLeaverequestService.insertVeLeaverequest(veLeaverequest));
    }

    /**
     * 修改【请填写功能名称】
     */
 /*   @RequiresPermissions("system:leaverequest:edit")
    @GetMapping("/edit/{EmployeeID}")
    public String edit(@PathVariable("EmployeeID") Long EmployeeID, ModelMap mmap)
    {
        VeLeaverequest veLeaverequest = veLeaverequestService.selectVeLeaverequestByEmployeeID(EmployeeID);
        mmap.put("veLeaverequest", veLeaverequest);
        return prefix + "/edit";
    }
*/
    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:leaverequest:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VeLeaverequest veLeaverequest)
    {
        return toAjax(veLeaverequestService.updateVeLeaverequest(veLeaverequest));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:leaverequest:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(veLeaverequestService.deleteVeLeaverequestByEmployeeIDs(ids));
    }

    @RequiresPermissions("system:work:editnoauth")
    @GetMapping("/edit/{id}")
    public String editnoauth(@PathVariable("id") int id, ModelMap mmap)
    {
       VeDrivers veDrivers = iVeDriversService.selectVeDriversByDriverID((long)id);
        mmap.put("veDrivers",veDrivers);
        mmap.put("taskCommentVoList",veLeaverequestService.getTaskCommentList(veDrivers.getFlowInstantId()));
        System.out.println(veDrivers);
        return prefix + "/edit";
    }




    @RequiresPermissions("system:work:listfinish")
    @PostMapping("/listfinish")
    @ResponseBody
    public TableDataInfo listfinish(VeDrivers veDrivers)
    {
        startPage();
        List<VeDrivers> list = veLeaverequestService.finishTask(getUserId());
        return getDataTable(list);
    }

    @RequiresPermissions("system:work:editnoauth")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/editnoauthdata")
    @ResponseBody
    public AjaxResult editSaveNoAuthData(VeDrivers veDrivers)
    {
        //执行工作流,完成任务
        veLeaverequestService.completeTask(veDrivers.getFlowInstantId(),veDrivers.getAgree(),getUserId(),veDrivers.getComment(),veDrivers.getDriverID());
        return toAjax(200);
    }
}
